package com.woniuxy.microsysserver.listener;

import com.woniuxy.microsysserver.bean.AdminInfo;
import com.woniuxy.microsysserver.bean.OptInfo;
import com.woniuxy.microsysserver.mapper.OptMapper;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component
public class SysListener {

    @Resource
    private OptMapper optMapper;
    /**
     * @RabbitHandler 处理Rabbit数据
     * @RabbitListener(queues = {"emailQueue"}) 监听某一个队列
     */
    @RabbitHandler
    @RabbitListener(queues = {"loginQueue"})
    public void listener01(Map<String,Object> data){
        data.forEach((k,v)->{
            System.out.println(k + "-----" + v);
        });
        //将登录信息放置数据库
        Integer id = (Integer)data.get("id");
        String ip = (String) data.get("ip");
        AdminInfo adminInfo = new AdminInfo();
        adminInfo.setId(id);
        OptInfo optInfo = new OptInfo();
        optInfo.setAdminInfo(adminInfo);
        optInfo.setOpt(1);
        optInfo.setIp(ip);
        optMapper.add(optInfo);
    }
}
